<script type="text/html" template lay-done="layui.data.sendParams(d.params)">
  <div class="layui-form" lay-filter="form_online">
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label">商品名称</label>
        <div class="layui-word-aux layui-form-mid">
          {{d.params.name || ''}}
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">所属门店</label>
        <div class="layui-input-inline">
          <select name="store_id" lay-filter="store_id">
          </select>
        </div>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">销售库存</label>
      <div class="layui-input-inline">
        <input type="text" class="layui-input" lay-verify="required" name="left_count"
               value="{{d.params.left_count || 0}}">
      </div>
      <div class="layui-input-inline">
        <input type="checkbox" name="show_left_count" lay-skin="switch" lay-text="显示实时库存|不显示实时库存"
               {{ (!d.params.configs.show_left_count || d.params.configs.show_left_count==1)?'checked':''}}>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label"></label>
      <div class="layui-word-aux layui-form-mid">
        库存不能大于 {{d.params.available_tokens_count}}
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label">销售价格</label>
        <div class="layui-input-inline">
          <input type="text" class="layui-input" lay-verify="required" name="display_price"
                 value="{{d.params.display_price || ''}}">
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">限购数量</label>
        <div class="layui-input-inline" style="width: 50px">
          <input type="text" class="layui-input" lay-verify="required" name="buy_limit"
                 value="{{d.params.buy_limit || -1}}">
        </div>
        <div class="layui-input-inline layui-word-aux layui-form-mid">
          -1代表不限制
        </div>
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label">开始时间</label>
        <div class="layui-input-inline">
          <input type="text" id="start_time" class="layui-input" name="start_time" placeholder="默认上架时开始"
                 autocomplete="off" value="{{d.params.start_time || ''}}">
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">结束时间</label>
        <div class="layui-input-inline">
          <input type="text" id="end_time" class="layui-input" name="end_time" placeholder="默认下架时结束"
                 autocomplete="off" value="{{d.params.end_time || ''}}">
        </div>
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-footer">
        <label class="layui-form-label"></label>
        <div class="layui-input-inline">
          <input type="button" lay-submit lay-filter="submit_online" value="确认" class="layui-btn">
        </div>
      </div>
    </div>
  </div>
</script>
<script>
  layui.data.sendParams = function (obj) {
    console.log(obj)
    layui.use([], function () {
      let $ = layui.$
        , admin = layui.admin
        , form = layui.form
        , laydate = layui.laydate

      //加载门店
      admin.get('agent-admin/stores', function (res) {
        layui.each(res.data, function (index, store) {
          let opt = new Option(store.name, store.id);
          if (store.id === obj.store_id) {
            opt.selected = true;
            $('select[name="store_id"]').append(opt).attr('disabled', true)
          } else {
            if (store.mobile == obj.publisher_account) {
              $('select[name="store_id"]').append(opt)
            }
          }
        })
        form.render()
      })

      //日历初始化
      laydate.render({
        elem: '#start_time'
        , type: 'datetime'
      });
      laydate.render({
        elem: '#end_time'
        , type: 'datetime'
      });
    })
  }
</script>
